import json

filename = 'favorite_num.json'

try:
    with open(filename) as f:
       num = json.load(f)
except FileNotFoundError:
    num = input("请输入最喜欢的数:")
    with open(filename,'w') as f:
        json.dump(num,f)
        print(f"We will remember your favorite num is {num}")
else:
    print(f"Your favorite num is {num}")